/**  
 * All rights Reserved, Designed By <a href="www.itttq.com" target="_blank">www.itttq.com</a>
 * @date:   2018年1月2日 下午4:42:56
 * @Copyright: 2018 <a href="www.itttq.com" target="_blank">www.itttq.com</a> Inc. All rights reserved. 
 */  
package com.itttq.gshop.pbpm.provider;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.jdbc.SQL;

import com.itttq.gshop.domain.po.WareInfoPo;
import com.itttq.gshop.generic.util.Constants;
import com.itttq.gshop.pbpm.cmpt.mybatis.CustomerSQL;

/**   
 * @ClassName:  WareInfoPoSqlProvider
 * @author: 迷蝶
 * @date:   2018年1月2日 下午4:42:56 
 * @Description: TODO
 *     
 * @Copyright: 2018 <a href="www.itttq.com" target="_blank">www.itttq.com</a> Inc. All rights reserved. 
 */
public class WareInfoSqlProvider {
	public static final String TABLE_NAME = "ware_info";

	/**
	 * 查找的SQL语句组装<br>
	 * 约定：分页两个参数为：start - 起始位置； size- 每页数量
	 * 
	 * @param wareInfo
	 * @return
	 * @Author 迷蝶
	 * @return String
	 */
	public String findWareInfos(final WareInfoPo wareInfo) {
		return new CustomerSQL() {{
			SELECT("barcode,batching,brand_id,brand_name,category_id,category_name,code,create_time,creator_id,date_manufacture,express_fee,id,image_main,image_thumb,last_shelf_time,manufacturer,manufacturer_address,method_packing,method_storage,method_use,name,number_inventory,perform_standard,pkg,price_original,price_promotional,producing_area,production_license,score_promote,score_total,score_buy,send_address,shelf_life,specifications,status,summary,unit_name,update_time,updater_id,sales,flavor,hot,recommend,type_id,type_name,class_id,class_name,price_market ");
			FROM(TABLE_NAME);
			
			if (StringUtils.isNotBlank(wareInfo.getBarcode())) {
				WHERE("barcode=#{barcode}");
			}
			if (StringUtils.isNotBlank(wareInfo.getBatching())) {
				WHERE("batching=#{batching}");
			}
			if (null != wareInfo.getBrandId()) {
				WHERE("brand_id=#{brandId}");
			}
			if (null != wareInfo.getCategoryId()) {
				WHERE("category_id=#{categoryId}");
			}
			if (StringUtils.isNotBlank(wareInfo.getCode())) {
				WHERE("code=#{code}");
			}
			if (null != wareInfo.getCreatorId()) {
				WHERE("creator_id=#{creatorId}");
			}
			if (StringUtils.isNotBlank(wareInfo.getDateManufacture())) {
				WHERE("date_manufacture=#{dateManufacture}");
			}
			if (null != wareInfo.getExpressFee()) {
				WHERE("express_fee=#{expressFee}");
			}
			if (null != wareInfo.getLastShelfTime()) {
				WHERE("last_shelf_time=#{lastShelfTime}");
			}
			if (StringUtils.isNotBlank(wareInfo.getManufacturer())) {
				WHERE("manufacturer=#{manufacturer}");
			}
			if (StringUtils.isNotBlank(wareInfo.getMethodPacking())) {
				WHERE("method_packing=#{methodPacking}");
			}
			if (StringUtils.isNotBlank(wareInfo.getMethodStorage())) {
				WHERE("method_storage=#{methodStorage}");
			}
			if (StringUtils.isNotBlank(wareInfo.getMethodUse())) {
				WHERE("method_use=#{methodUse}");
			}
			if (StringUtils.isNotBlank(wareInfo.getName())) {
				WHERE("name LIKE CONCAT('%',#{name},'%' ) ");
			}
			if (null != wareInfo.getNumberInventory()) {
				WHERE("number_inventory=#{numberInventory}");
			}
			if (StringUtils.isNotBlank(wareInfo.getPerformStandard())) {
				WHERE("perform_standard=#{performStandard}");
			}
			if (StringUtils.isNotBlank(wareInfo.getPkg())) {
				WHERE("pkg=#{pkg}");
			}
			if (null != wareInfo.getPriceOriginal()) {
				WHERE("price_original=#{priceOriginal}");
			}
			if (null != wareInfo.getPricePromotional()) {
				WHERE("price_promotional=#{pricePromotional}");
			}
			if (null != wareInfo.getPriceMarket()) {
				WHERE("price_market=#{priceMarket}");
			}
			if (StringUtils.isNotBlank(wareInfo.getProducingArea())) {
				WHERE("producing_area=#{producingArea}");
			}
			if (StringUtils.isNotBlank(wareInfo.getProductionLicense())) {
				WHERE("production_license=#{productionLicense}");
			}
//			if (null != wareInfo.getScorePromote()) {
//				WHERE("score_promote=#{scorePromote}");
//			}
//			if (null != wareInfo.getScoreTotal()) {
//				WHERE("score_total=#{scoreTotal}");
//			}
//			if (null != wareInfo.getScoreBuy()) {
//				WHERE("score_buy=#{scoreBuy}");
//			}
			// score_promote,score_total,score_buy
			if (StringUtils.isNotBlank(wareInfo.getShelfLife())) {
				WHERE("shelf_life=#{shelfLife}");
			}
			if (StringUtils.isNotBlank(wareInfo.getSpecifications())) {
				WHERE("specifications=#{specifications}");
			}
			if (null != wareInfo.getStatus()) {
				WHERE("status=#{status}");
			}
			if (StringUtils.isNotBlank(wareInfo.getUnitName())) {
				WHERE("unit_name=#{unitName}");
			}
			if (null != wareInfo.getUpdaterId()) {
				WHERE("updater_id=#{updaterId}");
			}
			if (null != wareInfo.getHot()) {
				WHERE("hot=#{hot}");
			}
			if (null != wareInfo.getRecommend()) {
				WHERE("recommend=#{recommend}");
			}
			if (null != wareInfo.getTypeId()) {
				WHERE("type_id=#{typeId}");
			}
			if (null != wareInfo.getClassId()) {
				WHERE("class_id=#{classId}");
			}
			if(StringUtils.isNotBlank(wareInfo.getSortField())) {
				String sortField = wareInfo.getSortField();
				if(sortField.equals("price")) {
					sortField = "price_promotional";
				} else if(sortField.equals("time")) {
					sortField = "update_time";
				} else if(sortField.equals("sale")) {
					sortField = "sales";
				} else {
					sortField = null;
				}
				if(null != sortField) {
					ORDER_BY(sortField +" "+ (StringUtils.isBlank(wareInfo.getSortMethod()) ? "desc" : wareInfo.getSortMethod()));
				}
			} else {
				// 默认按销量降序
				ORDER_BY("sales");
			}
			if(null != wareInfo.getStart() && null != wareInfo.getSize()) {
				LIMIT(wareInfo.getStart(), wareInfo.getSize());
			}
		}}.toString();
	}
	
	/**
	 * 查找记录总数的SQL语句组装
	 * 
	 * @param wareInfo
	 * @return
	 * @Author 迷蝶
	 * @return String
	 */
	public String findWareInfoCount(final WareInfoPo wareInfo) {
		return new SQL() {{
			SELECT("count(*)");
			FROM(TABLE_NAME);
			if (StringUtils.isNotBlank(wareInfo.getBarcode())) {
				WHERE("barcode=#{barcode}");
			}
			if (StringUtils.isNotBlank(wareInfo.getBatching())) {
				WHERE("batching=#{batching}");
			}
			if (null != wareInfo.getBrandId()) {
				WHERE("brand_id=#{brandId}");
			}
			if (null != wareInfo.getCategoryId()) {
				WHERE("category_id=#{categoryId}");
			}
			if (StringUtils.isNotBlank(wareInfo.getCode())) {
				WHERE("code=#{code}");
			}
			if (null != wareInfo.getCreatorId()) {
				WHERE("creator_id=#{creatorId}");
			}
			if (StringUtils.isNotBlank(wareInfo.getDateManufacture())) {
				WHERE("date_manufacture=#{dateManufacture}");
			}
			if (null != wareInfo.getExpressFee()) {
				WHERE("express_fee=#{expressFee}");
			}
			if (null != wareInfo.getLastShelfTime()) {
				WHERE("last_shelf_time=#{lastShelfTime}");
			}
			if (StringUtils.isNotBlank(wareInfo.getManufacturer())) {
				WHERE("manufacturer=#{manufacturer}");
			}
			if (StringUtils.isNotBlank(wareInfo.getMethodPacking())) {
				WHERE("method_packing=#{methodPacking}");
			}
			if (StringUtils.isNotBlank(wareInfo.getMethodStorage())) {
				WHERE("method_storage=#{methodStorage}");
			}
			if (StringUtils.isNotBlank(wareInfo.getMethodUse())) {
				WHERE("method_use=#{methodUse}");
			}
			if (StringUtils.isNotBlank(wareInfo.getName())) {
				WHERE("name LIKE CONCAT('%',#{name},'%' ) ");
			}
			if (null != wareInfo.getNumberInventory()) {
				WHERE("number_inventory=#{numberInventory}");
			}
			if (StringUtils.isNotBlank(wareInfo.getPerformStandard())) {
				WHERE("perform_standard=#{performStandard}");
			}
			if (StringUtils.isNotBlank(wareInfo.getPkg())) {
				WHERE("pkg=#{pkg}");
			}
			if (null != wareInfo.getPriceOriginal()) {
				WHERE("price_original=#{priceOriginal}");
			}
			if (null != wareInfo.getPricePromotional()) {
				WHERE("price_promotional=#{pricePromotional}");
			}
			if (null != wareInfo.getPriceMarket()) {
				WHERE("price_market=#{priceMarket}");
			}
			if (StringUtils.isNotBlank(wareInfo.getProducingArea())) {
				WHERE("producing_area=#{producingArea}");
			}
			if (StringUtils.isNotBlank(wareInfo.getProductionLicense())) {
				WHERE("production_license=#{productionLicense}");
			}
			if (StringUtils.isNotBlank(wareInfo.getShelfLife())) {
				WHERE("shelf_life=#{shelfLife}");
			}
			if (StringUtils.isNotBlank(wareInfo.getSpecifications())) {
				WHERE("specifications=#{specifications}");
			}
			if (null != wareInfo.getStatus()) {
				WHERE("status=#{status}");
			}
			if (StringUtils.isNotBlank(wareInfo.getUnitName())) {
				WHERE("unit_name=#{unitName}");
			}
			if (null != wareInfo.getUpdaterId()) {
				WHERE("updater_id=#{updaterId}");
			}
			if (null != wareInfo.getHot()) {
				WHERE("hot=#{hot}");
			}
			if (null != wareInfo.getRecommend()) {
				WHERE("recommend=#{recommend}");
			}
			if (null != wareInfo.getTypeId()) {
				WHERE("type_id=#{typeId}");
			}
			if (null != wareInfo.getClassId()) {
				WHERE("class_id=#{classId}");
			}
		}}.toString();
	}
	
	/**
	 * 根据ID查找的SQL语句组装
	 * 
	 * @param id
	 * @return
	 * @Author 迷蝶
	 * @return String
	 */
	public String findWareInfoById(final Integer id) {
		return new SQL() {{
			SELECT("*");
			FROM(TABLE_NAME);
			WHERE("id = #{id}");
		}}.toString();
	}
	
	/**
	 * 增加的SQL语句组装
	 * 
	 * @param wareInfo
	 * @return
	 * @Author 迷蝶
	 * @return String
	 */
	public String addWareInfo(final WareInfoPo wareInfo) {
		return new SQL() {{
			INSERT_INTO(TABLE_NAME);
			if (StringUtils.isNotBlank(wareInfo.getBarcode())) {
				VALUES("barcode","#{barcode}");
			}
			if (StringUtils.isNotBlank(wareInfo.getBatching())) {
				VALUES("batching","#{batching}");
			}
			if (null != wareInfo.getBrandId()) {
				VALUES("brand_id","#{brandId}");
			}
			if (StringUtils.isNotBlank(wareInfo.getBrandName())) {
				VALUES("brand_name","#{brandName}");
			}
			if (null != wareInfo.getCategoryId()) {
				VALUES("category_id","#{categoryId}");
			}
			if (StringUtils.isNotBlank(wareInfo.getCategoryName())) {
				VALUES("category_name","#{categoryName}");
			}
			if (StringUtils.isNotBlank(wareInfo.getCode())) {
				VALUES("code","#{code}");
			}
			if (null != wareInfo.getCreatorId()) {
				VALUES("creator_id","#{creatorId}");
			}
			if (StringUtils.isNotBlank(wareInfo.getDateManufacture())) {
				VALUES("date_manufacture","#{dateManufacture}");
			}
			if (StringUtils.isNotBlank(wareInfo.getDescription())) {
				VALUES("description","#{description}");
			}
			if (null != wareInfo.getExpressFee()) {
				VALUES("express_fee","#{expressFee}");
			}
			if (StringUtils.isNotBlank(wareInfo.getImageMain())) {
				VALUES("image_main","#{imageMain}");
			}
			if (StringUtils.isNotBlank(wareInfo.getImageThumb())) {
				VALUES("image_thumb","#{imageThumb}");
			}
			if (null != wareInfo.getLastShelfTime()) {
				VALUES("last_shelf_time","#{lastShelfTime}");
			}
			if (StringUtils.isNotBlank(wareInfo.getManufacturer())) {
				VALUES("manufacturer","#{manufacturer}");
			}
			if (StringUtils.isNotBlank(wareInfo.getManufacturerAddress())) {
				VALUES("manufacturer_address","#{manufacturerAddress}");
			}
			if (StringUtils.isNotBlank(wareInfo.getMethodPacking())) {
				VALUES("method_packing","#{methodPacking}");
			}
			if (StringUtils.isNotBlank(wareInfo.getMethodStorage())) {
				VALUES("method_storage","#{methodStorage}");
			}
			if (StringUtils.isNotBlank(wareInfo.getMethodUse())) {
				VALUES("method_use","#{methodUse}");
			}
			if (StringUtils.isNotBlank(wareInfo.getName())) {
				VALUES("name","#{name}");
			}
			if (null != wareInfo.getNumberInventory()) {
				VALUES("number_inventory","#{numberInventory}");
			}
			if (StringUtils.isNotBlank(wareInfo.getPerformStandard())) {
				VALUES("perform_standard","#{performStandard}");
			}
			if (StringUtils.isNotBlank(wareInfo.getPkg())) {
				VALUES("pkg","#{pkg}");
			}
			if (null != wareInfo.getPriceOriginal()) {
				VALUES("price_original","#{priceOriginal}");
			}
			if (null != wareInfo.getPricePromotional()) {
				VALUES("price_promotional","#{pricePromotional}");
			}
			if (null != wareInfo.getPriceMarket()) {
				VALUES("price_market","#{priceMarket}");
			}
			if (StringUtils.isNotBlank(wareInfo.getProducingArea())) {
				VALUES("producing_area","#{producingArea}");
			}
			if (StringUtils.isNotBlank(wareInfo.getProductionLicense())) {
				VALUES("production_license","#{productionLicense}");
			}
			if (null != wareInfo.getScorePromote()) {
				VALUES("score_promote","#{scorePromote}");
			}
			if (null != wareInfo.getScoreTotal()) {
				VALUES("score_total","#{scoreTotal}");
			}
			if (null != wareInfo.getScoreBuy()) {
				VALUES("score_buy","#{scoreBuy}");
			}
			if (StringUtils.isNotBlank(wareInfo.getSendAddress())) {
				VALUES("send_address","#{sendAddress}");
			}
			if (StringUtils.isNotBlank(wareInfo.getShelfLife())) {
				VALUES("shelf_life","#{shelfLife}");
			}
			if (StringUtils.isNotBlank(wareInfo.getSpecifications())) {
				VALUES("specifications","#{specifications}");
			}
			if (null != wareInfo.getStatus()) {
				VALUES("status","#{status}");
			}
			if (StringUtils.isNotBlank(wareInfo.getSummary())) {
				VALUES("summary","#{summary}");
			}
			if (StringUtils.isNotBlank(wareInfo.getUnitName())) {
				VALUES("unit_name","#{unitName}");
			}
			if (null != wareInfo.getUpdaterId()) {
				VALUES("updater_id","#{updaterId}");
			}
			if (null != wareInfo.getSales()) {
				VALUES("sales","#{sales}");
			}
			if (null != wareInfo.getFlavor()) {
				VALUES("flavor","#{flavor}");
			}
			if (null != wareInfo.getHot()) {
				VALUES("hot","#{hot}");
			}
			if (null != wareInfo.getRecommend()) {
				VALUES("recommend", "#{recommend}");
			}
			if (null != wareInfo.getTypeId()) {
				VALUES("type_id","#{typeId}");
			}
			if (null != wareInfo.getClassId()) {
				VALUES("class_id","#{classId}");
			}
			if (StringUtils.isNotBlank(wareInfo.getTypeName())) {
				VALUES("type_name","#{typeName}");
			}
			if (null != wareInfo.getClassName()) {
				VALUES("class_name","#{className}");
			}
		}}.toString();
	}

	/**
	 * 修改的SQL语句组装
	 * 
	 * @param wareInfo
	 * @return
	 * @Author 迷蝶
	 * @return String
	 */
	public String updateWareInfo(final WareInfoPo wareInfo) {
		return new SQL() {{
			UPDATE(TABLE_NAME);
			
			if (StringUtils.isNotBlank(wareInfo.getFlavor())) {
				SET("flavor=#{flavor}");
			}
			if (StringUtils.isNotBlank(wareInfo.getBarcode())) {
				SET("barcode=#{barcode}");
			}
			if (StringUtils.isNotBlank(wareInfo.getBatching())) {
				SET("batching=#{batching}");
			}
			if (null != wareInfo.getBrandId()) {
				SET("brand_id=#{brandId}");
			}
			if (StringUtils.isNotBlank(wareInfo.getBrandName())) {
				SET("brand_name=#{brandName}");
			}
			if (null != wareInfo.getCategoryId()) {
				SET("category_id=#{categoryId}");
			}
			if (StringUtils.isNotBlank(wareInfo.getCategoryName())) {
				SET("category_name=#{categoryName}");
			}
			if (StringUtils.isNotBlank(wareInfo.getCode())) {
				SET("code=#{code}");
			}
			if (null != wareInfo.getCreatorId()) {
				SET("creator_id=#{creatorId}");
			}
			if (StringUtils.isNotBlank(wareInfo.getDateManufacture())) {
				SET("date_manufacture=#{dateManufacture}");
			}
			if (StringUtils.isNotBlank(wareInfo.getDescription())) {
				SET("description=#{description}");
			}
			if (null != wareInfo.getExpressFee()) {
				SET("express_fee=#{expressFee}");
			}
			if (StringUtils.isNotBlank(wareInfo.getImageMain())) {
				SET("image_main=#{imageMain}");
			}
			if (StringUtils.isNotBlank(wareInfo.getImageThumb())) {
				SET("image_thumb=#{imageThumb}");
			}
			if (null != wareInfo.getLastShelfTime()) {
				SET("last_shelf_time=#{lastShelfTime}");
			}
			if (StringUtils.isNotBlank(wareInfo.getManufacturer())) {
				SET("manufacturer=#{manufacturer}");
			}
			if (StringUtils.isNotBlank(wareInfo.getManufacturerAddress())) {
				SET("manufacturer_address=#{manufacturerAddress}");
			}
			if (StringUtils.isNotBlank(wareInfo.getMethodPacking())) {
				SET("method_packing=#{methodPacking}");
			}
			if (StringUtils.isNotBlank(wareInfo.getMethodStorage())) {
				SET("method_storage=#{methodStorage}");
			}
			if (StringUtils.isNotBlank(wareInfo.getMethodUse())) {
				SET("method_use=#{methodUse}");
			}
			if (StringUtils.isNotBlank(wareInfo.getName())) {
				SET("name=#{name}");
			}
			if (null != wareInfo.getNumberInventory()) {
				SET("number_inventory=#{numberInventory}");
			}
			if (StringUtils.isNotBlank(wareInfo.getPerformStandard())) {
				SET("perform_standard=#{performStandard}");
			}
			if (StringUtils.isNotBlank(wareInfo.getPkg())) {
				SET("pkg=#{pkg}");
			}
			if (null != wareInfo.getPriceOriginal()) {
				SET("price_original=#{priceOriginal}");
			}
			if (null != wareInfo.getPricePromotional()) {
				SET("price_promotional=#{pricePromotional}");
			}
			if (null != wareInfo.getPriceMarket()) {
				SET("price_market=#{priceMarket}");
			}
			if (StringUtils.isNotBlank(wareInfo.getProducingArea())) {
				SET("producing_area=#{producingArea}");
			}
			if (StringUtils.isNotBlank(wareInfo.getProductionLicense())) {
				SET("production_license=#{productionLicense}");
			}
			if (null != wareInfo.getScorePromote()) {
				SET("score_promote=#{scorePromote}");
			}
			if (null != wareInfo.getScoreTotal()) {
				SET("score_total=#{scoreTotal}");
			}
			if (null != wareInfo.getScoreBuy()) {
				SET("score_buy=#{scoreBuy}");
			}
			if (StringUtils.isNotBlank(wareInfo.getSendAddress())) {
				SET("send_address=#{sendAddress}");
			}
			if (StringUtils.isNotBlank(wareInfo.getShelfLife())) {
				SET("shelf_life=#{shelfLife}");
			}
			if (StringUtils.isNotBlank(wareInfo.getSpecifications())) {
				SET("specifications=#{specifications}");
			}
			if (null != wareInfo.getStatus()) {
				SET("status=#{status}");
			}
			if (StringUtils.isNotBlank(wareInfo.getSummary())) {
				SET("summary=#{summary}");
			}
			if (StringUtils.isNotBlank(wareInfo.getUnitName())) {
				SET("unit_name=#{unitName}");
			}
			if (null != wareInfo.getUpdaterId()) {
				SET("updater_id=#{updaterId}");
			}
			if (null != wareInfo.getSales()) {
				SET("sales=#{sales}");
			}
			if (null != wareInfo.getHot()) {
				SET("hot=#{hot}");
			}
			if (null != wareInfo.getRecommend()) {
				SET("recommend=#{recommend}");
			}
			if (null != wareInfo.getTypeId()) {
				SET("type_id=#{typeId}");
			}
			if (null != wareInfo.getClassId()) {
				SET("class_id=#{classId}");
			}
			if (StringUtils.isNotBlank(wareInfo.getTypeName())) {
				SET("type_name=#{typeName}");
			}
			if (null != wareInfo.getClassName()) {
				SET("class_name=#{className}");
			}
			WHERE("id = #{id}");
		}}.toString();
	}
	
	/**
	 * 根据ID删除的SQL语句组装
	 * 
	 * @param id
	 * @return
	 * @Author 迷蝶
	 * @return String
	 */
	public String delWareInfo(final Integer id) {
		return new SQL() {{
			DELETE_FROM(TABLE_NAME);
			WHERE("id = #{id}");
		}}.toString();
	}
	
	/**
	 * 根据商品ID条件批量更新商品库存数据。
	 * 
	 * @param map	key值为deduct表示扣减；key为return表示还回库存。value为商品对象，必须含ID、numberInventory。注意：此时传入的商品库存值为要扣减的库存
	 * @Author 迷蝶
	 * @return String
	 */
	public String updateInventoryBatch(final Map<String, List<WareInfoPo>> map) {
        StringBuilder sb = new StringBuilder();
        sb.append("UPDATE ").append(TABLE_NAME).append(" SET number_inventory = CASE ");
        String ids = "";
        if(null != map.get(Constants.OP_INVENTORY_REDUCT)) {
	        for (WareInfoPo ware : map.get(Constants.OP_INVENTORY_REDUCT)) {
	        	sb.append(" WHEN id= ").append(ware.getId()).append(" AND number_inventory > 0 THEN number_inventory - ").append(ware.getNumberInventory());
	            // 如果库存小于0，则设置为原库存。因为数据库定义-1为不限
	        	sb.append(" WHEN id= ").append(ware.getId()).append(" AND number_inventory < 0 THEN number_inventory ");
	            ids += (ids.length() > 0 ? ",":"") + ware.getId();
	        }
        }
        if(null != map.get(Constants.OP_INVENTORY_ADD)) {
	        for (WareInfoPo ware : map.get(Constants.OP_INVENTORY_ADD)) {
	        	sb.append(" WHEN id= ").append(ware.getId()).append(" AND number_inventory > -1 THEN number_inventory + ").append(ware.getNumberInventory());
	            // 如果库存=-1，则设置为原库存。因为数据库定义-1为不限
	        	sb.append(" WHEN id= ").append(ware.getId()).append(" AND number_inventory = -1 THEN number_inventory ");
	            ids += (ids.length() > 0 ? ",":"") + ware.getId();
	        }
        }
        sb.append(" END ");
        sb.append("WHERE id IN ").append("(").append(ids).append(")");
        return sb.toString();
	}
}
